
import type { Profile } from '@/types/user'
import Cookies from 'js-cookie'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('hm-user', () => {
  const token = ref(Cookies.get('token')||'')
  const setToken = (newToken:string)=>{
    token.value = newToken
    Cookies.set('token',newToken)
  }
  const removeToken = ()=>{
    token.value = ''
    Cookies.remove('token')
  }
  //用户信息
  const profile = ref<Profile>({} as Profile)
  //设置用户信息
  const setProfile = (val:Profile)=>{
    profile.value = val
  }
  //清空用户信息
  const clearProfile = ()=>{
    profile.value = {} as Profile
  }
  return {
    profile,
    setProfile,
    clearProfile,
    token,
    setToken,
    removeToken
  }
})
